﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>百度地图</title>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2&services=true"></script>


<style type="text/css">
*{color: #000000;font-size:10pt}
body{
	margin:0px
}
</style>

</head>
<body>
<div style="width:100%;border:1px solid gray" id="container">
</div>

	
<script type="text/javascript"> 

	function getUrlArgment(sArgName,thisdocument)
	{
		var sURL;
	
		if (thisdocument)
			sURL=thisdocument.location.toString();
		else
			sURL=location.toString()
	
		var tempStr,urlargment;
		sArgName=sArgName.toLowerCase();
	
		if (sURL.split("?").length==1)
			return "";
	
		urlargment=sURL.split("?")[1];
		tempStr=urlargment.split("&");
		for(i=0;i<tempStr.length;i++)
		{
			if (tempStr[i].toString().indexOf(sArgName+"=")==0)
				return tempStr[i].split("=")[1];
		}
		return "";
	}

	document.getElementById("container").style.height = document.documentElement.clientHeight + "px";
	var map,marker,point,imgcss;;
	map = new BMap.Map("container");
	   
    map.enableScrollWheelZoom();
    map.enableContinuousZoom();
	map.addControl(new BMap.MapTypeControl());          //添加地图类型控件
	
	var menu = new BMap.ContextMenu();
	var txtMenuItem = [
	{
		text:'从这里到锚点',
 		callback:function(e){
            var pStart = new BMap.Point(e.lng,e.lat); 
			var transit = new BMap.TransitRoute(map, {
			  renderOptions: {map: map}
			});      
            transit.search(pStart, point); //终点是确定值，以名
        }
	}
	];
	
	for(var i=0; i < txtMenuItem.length; i++){
		menu.addItem(new BMap.MenuItem(txtMenuItem[i].text,txtMenuItem[i].callback,100));
	}
	 map.addContextMenu(menu);
	

    //获得参数
    function getPars(str,par){
        var reg = new RegExp(par+"=((\\d+|[.,])*)","g");
        return reg.exec(str)[1];
    }
    function init(){
    		map.addControl(new BMap.NavigationControl());
		map.setCurrentCity(unescape(getUrlArgment("city"))); 

		
    }
    init();

    window.onload=function() {
        
		var _x=getPars(document.location,"point").split(",")[0];
		var _y=getPars(document.location,"point").split(",")[1];
		point = new BMap.Point(_x,_y);    // 创建点坐标
		//map.centerAndZoom(point,10);
		map.centerAndZoom(point,parseInt(getPars(document.location,"zoom")));                     // 初始化地图,设置中心点坐标和地图级别。
		marker = new BMap.Marker(point);
		map.addOverlay(marker);
        
		var infoWindow = new BMap.InfoWindow(unescape(getUrlArgment("content")));  // 创建信息窗口对象
		marker.openInfoWindow(infoWindow);

		marker.addEventListener("click", function(e){
			var infoWindow = new BMap.InfoWindow(unescape(getUrlArgment("content")));  // 创建信息窗口对象
			marker.openInfoWindow(infoWindow);
		});

    }
    

</script>


 
</body>
</html>

